package com.etogc.http;

import android.graphics.Bitmap;
import android.util.Log;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.etogc.util.GcUrl;

/**
 * Created by ZeroVoid on 2018-3-14.
 */

public class UploadImageUtil {
    //设置请求的内容类型
    private static final String boundary = "apiclient-" + System.currentTimeMillis();
    private static final String mimeType = "multipart/form-data;boundary=" + boundary;

    //保存内容的数组集合
    private byte[] multipartBody;
    //需要上传的图片
    private Bitmap bitmap;

    //通过MultipartRequest上传图片的方法
    public static void uploadAvatarByMultipart(byte[] multipartBody) {
        MultipartRequest request = new MultipartRequest(GcUrl.UPLOAD_HEAD, multipartBody, new Response.Listener() {
            @Override
            public void onResponse(Object o) {
                Log.e("UPLOAD", String.valueOf(o));
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Log.e("UPLOAD", String.valueOf(volleyError));
            }
        }) ;

        VolleyHttpUtil.getInstance().addToQueue(request);
    }
}
